import { ObjCreate } from "../../common/ObjCreate";
import { ResFileConst } from "../../../resource/ResFileConst";
import { GlobalStyle } from "../../../../common/global/GlobalStyle";
import { LoaderManager } from "../../../../../com/gengine/resource/LoaderManager";
import { SWeddingStatus } from "../../../../../Message/Public/SWeddingStatus";
import { EWeddingStatus } from "../../../../../Message/Game/EWeddingStatus";
import { ProcessCellType } from "../defin/ProcessCellType";
import { ProcessState } from "../defin/ProcessState";
import { Language } from "../../../../../extend/language/Language";
import { GButton } from "../../../../../com/mui/controls/GButton";
import { Dispatcher } from "../../../../mvc/core/Dispatcher";
import { DataEvent } from "../../../events/DataEvent";
import { EventName } from "../../../mvc/EventName";
import { GLoadedButton } from "../../../../../com/mui/controls/GLoadedButton";
type int = number;
//class MarryProcessCell
    
    export  class MarryProcessCell /* flash.display.Sprite */
    {
        constructor()
        {
            
            this.createChildren();
            return;
        }

        /* internal  */createChildren(): void
        {
            this._spClick = new Object /* flash.display.Sprite */();
            this.addChild(this._spClick);
            this._btnProcess = ObjCreate.createGLoadedButton(ResFileConst.MarryProcessBtn, 0, 0, 38, 31, this._spClick);
            this._imgProcess = new Object /* flash.display.Bitmap */();
            this._imgProcess.x = 50;
            this._imgProcess.y = 10;
            this._spClick.addChild(this._imgProcess);
            this._spClick.buttonMode = true;
            this._tfDes = new Object /* flash.text.TextField */();
            this._tfDes.x = 30;
            this._tfDes.y = 50;
            this._tfDes.width = 325;
            this._tfDes.height = 160;
            this._tfDes.multiline = true;
            this._tfDes.wordWrap = true;
            this._tfDes.defaultTextFormat = GlobalStyle.textFormat1;
            this.addChild(this._tfDes);
            this._spClick.addEventListener(flash.events.MouseEvent.CLICK, this.onSpClick);
            return;
        }

        /* internal  */onSpClick(arg1: Object /* flash.events.MouseEvent */): void
        {
            this.showDes();
            return;
        }

        public updateData(arg1: string, arg2: string): void
        {
            this._tfDes.htmlText = "<textFormat leading = \'5\'>" + arg2 + "</textFormat>";
            LoaderManager.instance.load(arg1, this.onLoaded);
            return;
        }

        public updateState(arg1: string, arg2: SWeddingStatus): void
        {
            var loc1=false;
            this._processCellType = arg1;
            if (!this._tfState) 
            {
                this._tfState = ObjCreate.createTextField("", 240, 12, 100, 20, this);
            }
            if (!this._opLinkBtn) 
            {
                this._opLinkBtn = ObjCreate.createGButton("", 240, 29, 100, 20, this, "LinkButton");
                this._opLinkBtn.addEventListener(flash.events.MouseEvent.CLICK, this.onLinkBtnClick);
            }
            loc1 = !(!arg2 || arg2.status == EWeddingStatus._EWeddingStatusNotBook || arg2.status == EWeddingStatus._EWeddingStatusCanBook || arg2.status == EWeddingStatus._EWeddingStatusServerDown);
            var loc2=arg1;
            switch (loc2) 
            {
                case ProcessCellType.Register:
                {
                    if (arg2) 
                    {
                        this.updateStateText(ProcessState.Complete);
                    }
                    else 
                    {
                        this.updateStateText(ProcessState.UnComplete);
                    }
                    this._opLinkBtn.visible = false;
                    break;
                }
                case ProcessCellType.Book:
                {
                    if (!loc1 || arg2.status == EWeddingStatus._EWeddingStatusFail) 
                    {
                        this.updateStateText(ProcessState.UnComplete);
                    }
                    else 
                    {
                        this.updateStateText(ProcessState.Complete);
                    }
                    this._opLinkBtn.visible = arg2 && !loc1;
                    this._opLinkBtn.label = this.BookNow;
                    break;
                }
                case ProcessCellType.Inivte:
                {
                    if (!loc1 || arg2.status == EWeddingStatus._EWeddingStatusFail) 
                    {
                        this.updateStateText(ProcessState.UnComplete);
                    }
                    else if (arg2.status == EWeddingStatus._EWeddingStatusWeddingCar || arg2.status == EWeddingStatus._EWeddingStatusHadBooked) 
                    {
                        this.updateStateText(ProcessState.InProcess);
                    }
                    else 
                    {
                        this.updateStateText(ProcessState.Complete);
                    }
                    if (arg2 && (arg2.status == EWeddingStatus._EWeddingStatusWeddingCar || arg2.status == EWeddingStatus._EWeddingStatusHadBooked)) 
                    {
                        this._opLinkBtn.visible = true;
                        this._opLinkBtn.label = this.InviteNow;
                    }
                    else 
                    {
                        this._opLinkBtn.visible = false;
                    }
                    break;
                }
                case ProcessCellType.Parade:
                {
                    if (arg2 && (arg2.status == EWeddingStatus._EWeddingStatusWeddingCar || arg2.status == EWeddingStatus._EWeddingStatusSuccess)) 
                    {
                        this.updateStateText(ProcessState.Complete);
                    }
                    else 
                    {
                        this.updateStateText(ProcessState.UnComplete);
                    }
                    this._opLinkBtn.visible = false;
                    break;
                }
                case ProcessCellType.Wedding:
                {
                    if (arg2 && arg2.status == EWeddingStatus._EWeddingStatusSuccess) 
                    {
                        this.updateStateText(ProcessState.Complete);
                    }
                    else 
                    {
                        this.updateStateText(ProcessState.UnComplete);
                    }
                    this._opLinkBtn.visible = false;
                    break;
                }
            }
            return;
        }

        /* internal  */updateStateText(arg1: int): void
        {
            var loc1=arg1;
            switch (loc1) 
            {
                case ProcessState.Complete:
                {
                    this._tfState.htmlText = Language.getString(43628);
                    break;
                }
                case ProcessState.UnComplete:
                {
                    this._tfState.htmlText = Language.getString(43629);
                    break;
                }
                case ProcessState.InProcess:
                {
                    this._tfState.htmlText = Language.getString(43630);
                    break;
                }
            }
            return;
        }

        /* internal  */onLinkBtnClick(arg1: Object /* flash.events.MouseEvent */): void
        {
            var loc1=arg1.currentTarget as GButton;
            var loc2=loc1.label;
            if (loc2 != this.BookNow) 
            {
                if (loc2 == this.InviteNow) 
                {
                    Dispatcher.dispatchEvent(new DataEvent(EventName.MarryNPCInviteGuests));
                }
            }
            else 
            {
                Dispatcher.dispatchEvent(new DataEvent(EventName.MarryNPCBookingScene));
            }
            return;
        }

        /* internal  */onLoaded(arg1: Object): void
        {
            this._imgProcess.bitmapData = arg1.bitmapData as Object /* flash.display.BitmapData */;
            return;
        }

        public showDes(): void
        {
            if (!this._isShow) 
            {
                this._isShow = true;
                this._tfDes.mouseEnabled = false;
                this._btnProcess.enabled = false;
                this.addChild(this._tfDes);
                this.dispatchEvent(new DataEvent(EventName.MarryShowProcess));
            }
            return;
        }

        public hideDes(): void
        {
            this._isShow = false;
            if (this._tfDes && this._tfDes.parent) 
            {
                this._tfDes.parent.removeChild(this._tfDes);
                this._tfDes.mouseEnabled = true;
                this._btnProcess.enabled = true;
            }
            return;
        }

        public /* override */ get height(): number
        {
            if (this._isShow) 
            {
                return 180;
            }
            return 40;
        }

        /* internal */ /* const */BookNow: string=Language.getString(43631);

        /* internal */ /* const */InviteNow: string=Language.getString(43632);

        /* internal */ /* var */_processCellType: string;

        /* internal */ /* var */_spClick: Object /* flash.display.Sprite */;

        /* internal */ /* var */_btnProcess: GLoadedButton;

        /* internal */ /* var */_imgProcess: Object /* flash.display.Bitmap */;

        /* internal */ /* var */_tfState: Object /* flash.text.TextField */;

        /* internal */ /* var */_opLinkBtn: GButton;

        /* internal */ /* var */_tfDes: Object /* flash.text.TextField */;

        /* internal */ /* var */_isShow: Boolean;
    }
